<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateMatchOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('match_orders', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('deposit_trade_queue_id')->coment('入金单 id');
            $table->unsignedInteger('withdraw_trade_queue_id')->coment('出金单 id');
            $table->unsignedDecimal('amount',30,0)->comment('撮合的金额');
            $table->string('deposit_proof_img_url')->nullable()->comment('入金凭证图片地址');
            $table->unsignedBigInteger('deposit_confirm_at')->nullable()->comment('入金确认时间');
            $table->unsignedBigInteger('withdraw_confirm_at')->nullable()->comment('出金确认时间');
            $table->unsignedBigInteger('deposit_arbitration_at')->nullable()->comment('发起人申诉时间');
            $table->unsignedBigInteger('withdraw_arbitration_at')->nullable()->comment('提现人申诉时间');

            $table->unsignedBigInteger('created_at')->comment('匹配成功的时间');
            $table->unsignedBigInteger('updated_at')->comment('管理员操作时间');
            $table->boolean('is_manual')->default(true)->comment('手动 true | 自动就是 false');

            $table->foreign('deposit_trade_queue_id')->references('id')->on('trade_queues');
            $table->foreign('withdraw_trade_queue_id')->references('id')->on('trade_queues');

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('match_orders');
    }
}
